package common.hua.com.mycontrolactivity;


import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.Toast;

import com.hua.common.BaseActivity;
import com.hua.common.commonview.DropControl;
import com.hua.common.commonview.RefreshLayout;

import common.hua.com.myapplication.R;

/**
 * 下拉刷新控件测试界面
 * @author huaxiaolin_pc
 *
 */
public class RefreshActivity extends BaseActivity implements OnClickListener {

	private RefreshLayout layout = null;
	private Button stopBt, replaceBt = null;
	private WebView webView = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentViewItem(R.layout.refershactivitylayout);
		this.initViews();
		this.setPageTitle("下拉刷新");
	}

	@SuppressLint("SetJavaScriptEnabled")
	private void initViews() {
		this.stopBt = (Button) this.findViewById(R.id.bt);
		this.stopBt.setOnClickListener(this);
		this.replaceBt = (Button) this.findViewById(R.id.replaceheardview);
		this.replaceBt.setOnClickListener(this);

		this.layout = (RefreshLayout) this.findViewById(R.id.refresh);
		this.layout.setRefreshListener(new RefreshLayout.MyRefreshListener() {
			@Override
			public void reFreshing() {
				Toast.makeText(RefreshActivity.this, "开始刷新", Toast.LENGTH_LONG).show();
			}
		});

		this.webView = (WebView) this.findViewById(R.id.web);

		this.webView.setWebViewClient(new WebViewClient() {
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(url);
				return true;
			}
		});
		/**
		 * 设置WebView的属性
		 */
		WebSettings webSettings = webView.getSettings();
		webSettings.setJavaScriptEnabled(true); // 支持Javascript脚本语言
		webSettings.setAllowFileAccess(true); // 允许WebView访问文件数据
		webSettings.setBuiltInZoomControls(true); // 支持内容缩放控制
		this.webView.loadUrl("https://m.taobao.com/?sprefer=sypc00#index");
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.bt:
				layout.stop();
				break;
			case R.id.replaceheardview:
				layout.stop();
				if (this.layout.getIsNativeHeardView()) {
					this.layout.setHeardView(new DropControl(this));
				} else {
					this.layout.setHeardView(null);
				}
				break;
		}
	}

}
